//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package net.mingsoft.config;

import java.util.concurrent.ThreadPoolExecutor.CallerRunsPolicy;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

@Configuration
@EnableAsync
public class AsyncConfig {
    @Value("${ms.thread.core-pool-size:10}")
    private int corePoolSize;
    @Value("${ms.thread.max-pool-size:50}")
    private int maxPoolSize;
    @Value("${ms.thread.core-pool-size:1000}")
    private int queueCapacity;
    @Value("${ms.thread.keep-alive-seconds:300}")
    private int KeepAliveSeconds;
    @Value("${ms.thread.thread-name-prefix:lh-something-}")
    private String threadNamePrefix;
    @Value("${ms.thread.await-termination-seconds:60}")
    private int awaitTerminationSeconds;

    public AsyncConfig() {
    }

    @Bean
    public ThreadPoolTaskExecutor threadPoolTaskExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(this.corePoolSize);
        executor.setMaxPoolSize(this.maxPoolSize);
        executor.setQueueCapacity(this.queueCapacity);
        executor.setKeepAliveSeconds(this.KeepAliveSeconds);
        executor.setThreadNamePrefix(this.threadNamePrefix);
        executor.setAllowCoreThreadTimeOut(true);
        executor.setWaitForTasksToCompleteOnShutdown(true);
        executor.setAwaitTerminationSeconds(this.awaitTerminationSeconds);
        executor.setRejectedExecutionHandler(new CallerRunsPolicy());
        executor.initialize();
        return executor;
    }
}
